package com.mtbu.dao;
import java.util.ArrayList;
import java.util.List;

import my.myorm.tool.jdbc.ResultList;
import my.myorm.tool.jdbc.SQLExecutor;
import my.myorm.tool.jdbc.SQLManager;
import my.myorm.tool.orm.TableBeanMap;

import com.mtbu.bean.Step;
import com.mtbu.bean.SysUser;
import com.mtbu.dao.base.StepDaoBase;
public final class  StepDao extends StepDaoBase{
   public   String getSplit(Step step) throws Exception{
        return "";
    }
   
   public List<Step> findStepByProject(int projectId) throws Exception{
	    
	   String byProjectId= TableBeanMap.getColumnName(Step.class, "projectId");

	   
	   String sql="select * from " + getTable() + " where " + byProjectId + "=?" ;
	   
	   SQLExecutor dbconn= SQLManager.getSQLExecutor(super.getDsName(),true);
	   dbconn.addParam(projectId);

	   
	   List<Step> res = new ArrayList<Step>();
	   	   
	   ResultList rs = dbconn.query(sql, false, null);
	   for (int i = 0 ; i < rs.size() ; i++) {
		   res.add(rs.get(i).get(Step.class));
	   }
		
	   return res;
   }
   
   
   public Step findStepByProjectAndType(int projectId,int type) throws Exception{
	    
	   String byProjectId= TableBeanMap.getColumnName(Step.class, "projectId");
	   String byType= TableBeanMap.getColumnName(Step.class, "type");
	   
	   String sql="select * from " + getTable() + " where " + byProjectId + "=?" + " and ";
	   sql += byType + "=?" ;
	   
	   SQLExecutor dbconn= SQLManager.getSQLExecutor(super.getDsName(),true);
	   dbconn.addParam(projectId);
	   dbconn.addParam(type);
	   return dbconn.queryForBean(sql,Step.class);
   }
   
   public Step findStepByProjectAndPrestepid(int projectId,int prestepId) throws Exception{
	    
	   String byProjectId= TableBeanMap.getColumnName(Step.class, "projectId");
	   String byPrestepId= TableBeanMap.getColumnName(Step.class, "prestepid");
	   
	   String sql="select * from " + getTable() + " where " + byProjectId + "=?" + " and ";
	   sql += byPrestepId + "=?" ;
	   
	   SQLExecutor dbconn= SQLManager.getSQLExecutor(super.getDsName(),true);
	   dbconn.addParam(projectId);
	   dbconn.addParam(prestepId);
	   return dbconn.queryForBean(sql,Step.class);
   }
   
   public Step findStepByProjectAndNextstepid(int projectId,int nextstepId) throws Exception{
	    
	   String byProjectId= TableBeanMap.getColumnName(Step.class, "projectId");
	   String byNextstepId= TableBeanMap.getColumnName(Step.class, "nextstepId");
	   
	   String sql="select * from " + getTable() + " where " + byProjectId + "=?" + " and ";
	   sql += byNextstepId + "=?" ;
	   
	   SQLExecutor dbconn= SQLManager.getSQLExecutor(super.getDsName(),true);
	   dbconn.addParam(projectId);
	   dbconn.addParam(nextstepId);
	   return dbconn.queryForBean(sql,Step.class);
   }
   
}
